import ListBaseStore from './ListBaseStore';
import Apis from '../apis/car';
import { message } from 'antd';
import { observable, action } from 'mobx';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;
export default class CarTypeStore extends ListBaseStore {
  // 加载列表数据
	@action doTableLoading = (params, callbackfun) => {
	  this.showLoading(true);
	  Apis.getCarType(params).then(
	    (result) => {
	      if (result && result.isRight == 1) {
	        const sessionkey = result.sessionkey;
	        this.sessionkey = sessionkey;
	        this.tableStore.getDatas(sessionkey, 1);
	      }
	      if (callbackfun) {
	        callbackfun(result.isRight);
	      }
	      this.showLoading(false);
	    },
	  );
	}

	initCarTypeForm() {
	  const conditioninfo = [
	    {
	      defaultshow: true,
	      title: getLabel(17630, '车辆类型'),
	      items: [
	        { colSpan: 2, conditionType: 'INPUT', domkey: ['id'], fieldcol: 12, isQuickSearch: false, label: 'id', labelcol: 6, precision: 0, viewAttr: 1 },
	        { colSpan: 2, conditionType: 'INPUT', rules: 'required|string', domkey: ['name'], fieldcol: 12, isQuickSearch: false, label: getLabel(195, '名称'), labelcol: 6, precision: 0, viewAttr: 3 },
	        { colSpan: 2, conditionType: 'INPUT', domkey: ['description'], fieldcol: 12, isQuickSearch: false, label: getLabel(433, '描述'), labelcol: 6, precision: 0, viewAttr: 2 },
	        { colSpan: 2, conditionType: 'INPUT', rules: 'required|numeric', domkey: ['usefee'], fieldcol: 12, isQuickSearch: false, label: getLabel(1491, '费用'), labelcol: 6, precision: 0, viewAttr: 3, tip: getLabel(17647, '元/公里') },
	      ],
	    },
	  ];
	  this.conditioninfo = conditioninfo;
	  this.initFormFields(conditioninfo);
	}

	saveOrUpdateCarType(params = {}, callbackfun) {
	  this.showLoading(true);
	  Apis.saveOrUpdateCarType(params).then(
	    (result) => {
	      if (result && result.status == '1') {
	        message.success(getLabel(385859, '保存车辆类型成功'));
	        this.doTableLoading();
	      } else {
	        message.error(getLabel(385860, '保存车辆类型失败'));
	      }
	      if (callbackfun) {
	        callbackfun();
	      }
	      this.showLoading(false);
	    },
	  );
	}

	deleteCarType(params = {}, callbackfun) {
	  this.showLoading(true);
	  Apis.deleteCarType(params).then(
	    (result) => {
	      if (result && result.status == '1') {
	        message.success(getLabel(385862, '删除车辆类型成功'));
	        this.doTableLoading();
	      } else if (result && result.status == '-1') {
	        message.error(result.error);
	      } else {
	        message.error(getLabel(385863, '删除车辆类型失败'));
	      }
	      if (callbackfun) {
	        callbackfun();
	      }
	      this.showLoading(false);
	    },
	  );
	}
}
